#include<bits/stdc++.h>
using namespace std;
struct color{
    int x;
    bool y;
}a[200006];
int t;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int w=0;w<t;w++){
        int maxn=0,minn=9000000,n,c=0;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a[i].x;
            maxn=max(maxn,a[i].x);
            minn=min(minn,a[i].x);
        }
        int mid=(maxn+minn)/2;
        for(int i=0;i<n;i++){
            if(a[i].x>=mid)a[i].y=true;
            else a[i].y=false;
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<i;j++){
                if(a[i].x==a[j].x&&a[i].y==a[j].y&&a[i].x>0&&a[j].x>0){
                    c+=a[i].x;
                    a[i].x=-1;
                    a[j].x=-1;
                }
            }
        }
        cout<<c<<endl;
    }
    return 0;
}
